﻿using AgencyManagerSystem.AsmType;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.Core;
using AgencyManagerSystem.Core.Utility;
using AgencyManagerSystem.DataFetcher;
using AgencyManagerSystem.Model;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Net;

namespace AgencyManagerSystem.Controllers
{
    public class CustPriceController : MyControllerBase
    {
        CustPriceManager manager;
        CustPriceFetcher fetcher;
        public CustPriceController() : base()
        {
            this.manager = new CustPriceManager();
            this.fetcher = new CustPriceFetcher();
        }
        [HttpGet]
        [Authorize]
        public AsmObject<CustPriceModel> Get(int production,string unit,string date)
        {
            LogHelper.Debug(this.GetType(), String.Format("GET:[RQS|{1}]{0}", Util.ConvertToJson(production), RequestIp));
            var prof = MyHttpContextHelper.ToFullUserProfile(profile);
            var customer = fetcher.GetByProductionAndCustomer(production, prof.UserCode,unit,date);
            
            DBHelper.Commit( true);
            AsmObject<CustPriceModel> result = null;
            if (customer != null)
                result = new AsmObject<CustPriceModel>() { Data = customer, Message = "操作成功", Result = AmsCode.Succ };
            else
                result = new AsmObject<CustPriceModel>() { Data = customer, Message = "无法找到数据", Result = AmsCode.DataNotFound };
            LogHelper.Debug(this.GetType(), String.Format("GET:[RSP|{1}]{0}", Util.ConvertToJson(result), RequestIp));
            return result;
        }
    }
}